package com.example.park2212.house

import android.graphics.Color
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.lib_base.entity.HouseBeanItem
import com.example.park2212.R

class HouseItemAdapter(vm:HoursViewModel):BaseQuickAdapter<HouseBeanItem, BaseViewHolder>(R.layout.item_house){
    lateinit var vm:HoursViewModel
    init {
        this.vm = vm
    }
    override fun convert(helper: BaseViewHolder, item: HouseBeanItem) {
        helper.setText(R.id.room,"${item.id}室")
        helper.setText(R.id.qiye,"企业：${item.enterpriseName}")
        helper.setText(R.id.mianji,"面积：${item.area}")
        val tv_status = helper.getView<TextView>(R.id.status)
        if (item.rented){
            tv_status.setText("已出租")
            tv_status.setBackgroundResource(R.drawable.shape_solid_darkgreen)

        }else{
            tv_status.setText("未出租")
            tv_status.setBackgroundResource(R.drawable.shape_solid_orange)
        }

        tv_status.setOnClickListener {
            if (tv_status.text.toString() == "未出租"){
                vm.rentHouse(item.id,vm.getDate(System.currentTimeMillis()))
                item.rented = true
            }else{
                vm.unrentHouse(item.id)
                item.rented = false
            }
            notifyDataSetChanged()
        }

    }
}